package com.example.xxtautosignjava.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.xxtautosignjava.common.R;
import com.example.xxtautosignjava.entity.QrcodeSign;
import com.example.xxtautosignjava.service.QrcodeSignService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lee
 * @since 2023-02-27
 */
@RestController
@RequestMapping("/xxtautosignjava/qrcode-sign")
public class QrcodeSignController {
    @Resource
    private QrcodeSignService  signService;

    @PostMapping("add")
    public R addEnc(@RequestBody QrcodeSign qrcodeSign){
        QueryWrapper wrapper =new QueryWrapper();
        wrapper.eq("aid",qrcodeSign.getAid());
        if (signService.count(wrapper)==0){
            signService.save(qrcodeSign);
        }

        return R.ok().data("qrcodeSign",qrcodeSign);
    }
    @ApiOperation("根据aic 获取课程信息 包括enc")
    @GetMapping("getByAid/{id}")
    public R getByAid(String aid){
        QueryWrapper wrapper =new QueryWrapper();
        wrapper.eq("aid",aid);
        QrcodeSign one = signService.getOne(wrapper);
        return R.ok().data("one",one);
    }
    @ApiOperation("获取数据库里面所有信息，按时间排序")
    @GetMapping("getEncInfo")
    public R getEncInfo(){
        QueryWrapper wrapper =new QueryWrapper();
        wrapper.orderByDesc("gmt_create");
        List<QrcodeSign> list = signService.list(wrapper);
        return R.ok().data("list",list);
    }


}


